import jmespath
from aaa import BaseRequest, outer
from loguru import logger


class Circle(BaseRequest):  # 接口

    @outer
    def selent(self):
        url = self.url + '/list/tree'
        response = self.get(url)
        logger.info(response)
        return response

    @outer
    def add(self):  # 添加圈层
        url = self.url + '/save'
        json_data = self.faker.Create_Data()
        response = self.post(url, json_data)
        logger.info(response)
        return {'response': response, 'test_data': json_data}

    @outer
    def delete(self, del_id):
        url = self.url + f'/delete/{del_id}'
        response = self.post(url)
        logger.info(response)
        return response


if __name__ == '__main__':
    circle = Circle()
    add_result = circle.add()
    save_id = add_result['response']['data']
    test_data = add_result['test_data']
    data = circle.selent()
    assert jmespath.search("data[?id == `{}`].realName".format(save_id), data)[0] == test_data['realName']
    Circle().delete(save_id)
